Whats App Integration
This document explains the WhatsApp Web integration for bulk messaging, focusing on QR code authentication, session and connection lifecycle, contact import from CSV, Excel, and text files, message composition with personalization, bulk sending with configurable delays, and real-time status monitoring. It also covers troubleshooting and security best practices.
The integration spans three layers:
Electron renderer (React UI) for user interaction and status display
Electron main process for WhatsApp Web.js client lifecycle and IPC
Python backend for advanced contact processing and validation
BulkMailer.jsx"] end subgraph "Electron Main" MAIN["main.js
IPC Handlers"] PRELOAD["preload.js
Exposed API"] end subgraph "WhatsApp Web" WAPI["whatsapp-web.js
LocalAuth"] QR["qrcode"] end subgraph "Python Backend" PYAPP["Flask app.py"] EXTRACT["extract_contacts.py"] PARSE["parse_manual_numbers.py"] VALID["validate_number.py"] end UI --> PRELOAD PRELOAD --> MAIN MAIN --> WAPI MAIN --> QR UI --> PYAPP PYAPP --> EXTRACT PYAPP --> PARSE PYAPP --> VALID
Diagram sources
Section sources
WhatsAppForm: UI for connecting, scanning QR, managing contacts, composing messages, and viewing activity logs.
BulkMailer: Orchestrates WhatsApp lifecycle, listens to status events, and coordinates IPC with the main process.
Electron Main: Initializes the WhatsApp client, handles QR generation, connection events, and bulk sending loop with delays.
Preload Bridge: Exposes secure IPC methods to the renderer for WhatsApp operations.
Python Backend: Provides REST endpoints for contact import and parsing, including CSV/Excel/Text support and number validation.
Section sources
End-to-end flow for authentication and sending:
Diagram sources
QR Code Authentication and Session Lifecycle#
The main process creates a Client with LocalAuth and emits QR codes as data URLs.
The renderer displays QR until authentication succeeds or errors occur.
Logout triggers explicit client logout and cleanup of cached auth/session files.
Diagram sources
Section sources
Contact Import and Parsing#
CSV/Excel/Text import is supported via two paths:
Python backend REST endpoints for robust parsing and validation
Manual text parsing in the renderer using Pyodide for quick local processing
The renderer supports CSV/Text locally; Excel is noted as not yet supported in this UI path.
Diagram sources
Section sources
Message Composition and Personalization#
Users compose messages in the UI and can use a placeholder to personalize with contact names.
During sending, the message is personalized by replacing the placeholder with either the contact’s name or a default value.
Diagram sources
Section sources
Bulk Sending Implementation and Delays#
The main process sends messages sequentially to each contact.
It checks registration status before sending and applies delays to reduce spam risk.
Real-time progress is emitted via IPC to the renderer for display.
Diagram sources
Section sources
Real-time Status Monitoring#
The renderer subscribes to three event channels:
Connection status updates
QR code data URL updates
Per-message send status updates
These are displayed in the activity log with color-coded indicators.
Diagram sources
Section sources
Key runtime dependencies for the integration:
whatsapp-web.js: Core WhatsApp Web client and authentication
qrcode: QR code rendering for the UI
Pyodide and Python backend: Contact parsing and validation utilities
Diagram sources
Section sources
Sequential sending with delays reduces rate limits and improves reliability.
Using isRegisteredUser avoids unnecessary send attempts and reduces error noise.
QR generation occurs only once per session; caching and reuse minimize overhead.
Consider batching contacts and adding jitter to delays for natural pacing.
Common issues and resolutions:
QR code not loading
Refresh the client and retry; the UI provides a retry button when QR fails to load.
Ensure network connectivity and try again.
Authentication failures
Reinitialize the client and re-scan the QR.
Confirm the device is linked and not logged out elsewhere.
Rate limiting and spam detection
Increase delays between messages; the current implementation uses fixed delays.
Pause periodically and resume to avoid continuous bursts.
Contact import errors
Verify file format and encoding; supported formats include CSV, Excel (.xlsx/.xls), and Text.
Ensure phone numbers are valid and standardized before sending.
Section sources
Context isolation and secure IPC prevent direct Node.js access in the renderer.
LocalAuth stores session securely; logout clears cached auth files.
Input validation and sanitization are applied in the Python backend for numbers and contact parsing.
Use strong authentication for external services (Gmail/SMTP) and rotate credentials regularly.
Section sources
The integration provides a robust, user-friendly pathway to authenticate via QR, manage contacts, compose personalized messages, and send them reliably with real-time feedback. The architecture cleanly separates concerns across renderer, main process, and Python utilities, enabling maintainability and scalability.